<?php

/**
 * Resource loader
 *
 * @author     Mon Zafra <monzee@gmail.com>
 * @copyright  (c)2009 Mon Zafra
 * @package    Mz
 * @license    New BSD
 * @version    $Id: Resource.php 38 2009-02-18 17:12:39Z monzee $
 * @deprecated deprecated since r20
 */
class Mz_Resource
{
    /**
     *
     * @var Zend_Loader_PluginLoader
     */
    static protected $_loader;
    static protected $_registry;
    static protected $_paths;
    protected $_defaultPaths = array(
        'Form' => '../application/forms',
        'Plugin' => '../application/plugins',
    );

    public function __construct($paths=array(), $registry='resources')
    {
        self::$_paths = $paths + $this->_defaultPaths;
        $this->_registry = $registry;
    }

    static public function setPrefixPaths(array $paths)
    {
        self::$_paths = $paths;
    }

    static public function addPrefixPath($path, $prefix)
    {
        if (null !== self::$_loader) {
            self::$_loader->addPrefixPath($prefix, $path);
        } else {
            if (!isset(self::$_paths[$prefix])) {
                self::$_paths[$prefix] = $path;
            } else {
                if (!is_array(self::$_paths[$prefix])) {
                    self::$_paths[$prefix] = (array) self::$_paths[$prefix];
                }
                self::$_paths[$prefix][] = $path;
            }
        }
    }

    /**
     *
     * @return Zend_Loader_PluginLoader
     */
    static public function getLoader()
    {
        if (null === self::$_loader) {
            self::$_loader = new Zend_Loader_PluginLoader(self::$_paths, self::$_registry);
        }
        return self::$_loader;
    }

    /**
     *
     * @param mixed $loader
     * @return Mz_Resource
     */
    public function setLoader($loader)
    {
        self::$_loader = $loader;
        return $this;
    }

    static public function load($class)
    {
        $loader = self::getLoader();
        return $loader->load($class);
    }


}
